package com.northpool.operator.common.crypto;

import cn.hutool.crypto.SecureUtil;
import com.northpool.operator.annotation.InputParam;
import com.northpool.operator.annotation.InputParams;
import com.northpool.operator.annotation.OperatorInfo;
import com.northpool.operator.annotation.OutputParam;
import com.northpool.operator.annotation.OutputParams;
import com.northpool.operator.common.algorithm.OperatorTestBuild;
import com.northpool.operator.common.algorithm.TestParamBuilder;
import com.northpool.operator.param.ParamTool;
import com.northpool.operator.type.TypeEnum;
import com.northpool.operator.utils.StpOperatorHelper;


@OperatorInfo(
        ref = "EncryptOperator",
        name = "加密",
        version = "sha1",
        description = "字符串加解密算子"
)
@OutputParams({
        @OutputParam(ref = "sha1", name = "sha1值", desc = "字符串的sha1值")
})
public class Sha1EncryptOperator extends StpOperatorHelper {

    @InputParams({
            @InputParam(ref = "str", name = "待加密字符串", desc = "待sha1加密字符串", type = TypeEnum.STRING, required = true),
    })
    public Sha1EncryptOperator() {
    }

    public static void main(String[] args) {
        OperatorTestBuild.execute(Sha1EncryptOperator.class, TestParamBuilder.aBuilder()
                .param("str", "123456")
                .build());
    }

    @Override
    public void execute(ParamTool paramTool) throws Exception {
        String str = paramTool.getStr("str");

        String digestHex = SecureUtil.sha1(str);
        this.result("sha1", digestHex);
    }
}
